<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">
          云e办
        </div>
        <div class="userinfo">
          <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            {{ user.name }}
            <img :src="user.userFace">
          </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a">个人中心</el-dropdown-item>
              <el-dropdown-item command="settings">设置</el-dropdown-item>
              <el-dropdown-item command="logout">注销登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

        </div>


      </el-header>
      <el-container class="homeContainer">
        <el-aside width="200px">
          <el-menu router unique-opened>
            <el-submenu :index="index+'' "
                        v-for="(item,index) in routes"
                        :key="index"
                        v-if="!item.hidden">
              <template slot="title">
                <i :class="item.iconCls" style="color: #1ea9e7; margin-right: 5px"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item :index="child.path" v-for="(child,indexj) in item.children" :key="indexj">
                <span>{{ child.name }}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'" class="el-breadcrumb">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div v-if="this.$router.currentRoute.path =='/home'" class="homeWelcome">
            欢迎来到云e办系统
          </div>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>

  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem('user'))
    }
  },
  methods: {
    menuClick(index) {
      this.$router.push(index);
    },
    handleCommand(command) {
      if (command == 'logout') {
        this.$confirm('此操作将退出登录?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.postRequest('/logout');
          window.sessionStorage.removeItem('tokenStr');
          window.sessionStorage.removeItem('user');
          //跳转到首页
          this.$router.replace('/')
        }).catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: '已取消'
          // });
        });
      }
    }
  }
  ,
  computed: {
    routes() {
      return this.$store.state.routes;
    }

  }
}
</script>

<style scoped>
.homeHeader {
  background: #1ea9e7;
  display: flex;
  align-items: center;
  padding: 0 15px;
  box-sizing: border-box;
  top: 0;
  width: 100%;
  position: relative;
  height: 100px;
  z-index: 1000;
}

.homeHeader .title {
  font-size: 30px;
  font-family: 华文楷体;
  color: white;
}

.homeContainer {
  height: calc(100vh - 70px);
}

.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

.userinfo {
  float: right;
  text-align: right;
  position: fixed;
  right: 40px;
  cursor: pointer;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #935542;
}

.el-dropdown-link img {
  width: 24px;
  height: 24px;
  border-radius: 12px;
  align-items: center;
}

.el-icon-arrow-down {
  font-size: 12px;
}
.el-breadcrumb{
  padding-bottom: 8px;
}
.homeWelcome{
  text-align: center;
  font-size: 30px;
  color: #409EFF;
  font-family: 华文楷体;
  padding-top: 20px;
}

</style>